<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="copyright"
	content="All Rights Reserved, Copyright (C) 2013, Wuyeguo, Ltd." />
<title>贴吧管理</title>
<link href="${ctx}/resources/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="${ctx }/resources/easyui/themes/metro/easyui.css" />
<link rel="stylesheet" type="text/css" href="${ctx }/resources/css/icon.css" />
<script type="text/javascript" src="${ctx }/resources/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" charset="utf-8" src="${ctx}/resources/umeditor/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="${ctx}/resources/umeditor/umeditor.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/umeditor/lang/zh-cn/zh-cn.js"></script>
</head>
  
  <body>
  
	<table id="dg" class="easyui-datagrid"  ></table>
	
	<div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newTopic()">我要发帖</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="queryTopic()">查看</a>
    </div>
    
    <div id="dlg" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
        <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
            <div style="margin-bottom:10px">
            	<input name="topicid" id="topicid" type="hidden">
                <input name="title" class="easyui-textbox" required="true" label="标题:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="author" class="easyui-textbox" labelAlign="center"  required="true" label="作者:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="content" class="easyui-textbox" labelAlign="center"  required="true" label="内容:" style="width:100%">
            </div>
        </form>
    </div>
	
	<div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveTopic()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
    
	<script type="text/javascript">
		$("#dg").datagrid({
			title:'贴吧列表',//标题
			width:'100%',//宽度
			height:'400px',//高度
			iconCls:'icon-save',//图标
			pagination:true,//是否打开分页
			fitColumns:true,// 是否动分配列宽
			singleSelect:true,// 是否支持单行选中
			rownumbers:true,// 是否显示行号
			url:'${ctx}/topic/queryAllTopic.action',//json数据地址
			toolbar:'#toolbar',//工具栏
			pageSize:10,//默认的每页显示条数
			pageNumber:1,//加载时的页码
		    columns:[[//对url传回的json数据的解析
			           {field:'title',title:'标题',width:100,align:'center'},
			           {field:'author',title:'作者',width:100,align:'center'},
			           {field:'createdate',title:'时间',width:100,align:'center'},
			           {field:'clickamount',title:'浏览量',width:100,align:'center'}
			       ]]
		});
		
		function doSearch() {
			var params=$("#searchFrm").serialize();
			//alert(params);
			$("#dg").datagrid({
				url:'${ctx}/topic/queryAllTopic.action?'+params
				
			});
		}
		
		//添加
		var url;
		function newTopic(){
	        $('#dlg').dialog('open').dialog('center').dialog('setTitle','添加用户');
	        $('#fm').form('clear');
	        url = '${ctx}/topic/addTopic.action';
	    }
		
		 function saveTopic(){
			 $('#fm').form('submit',{
	             url: url,	                
	             onSubmit: function(){
	             	
	                 return $(this).form('validate');
	             },
	             success: function(result){
	                 var result = eval('('+result+')');
	                 $('#dlg').dialog('close');       // close the dialog
    	             $('#dg').datagrid('reload');    // reload the topic data
	                     $.messager.show({
	                         title: '提示',
	                         msg: result.msg
	                     });
	                     
	             }
	         });
	        }
		
		
		//查看
		function queryTopic() {
			var row = $('#dg').datagrid('getSelected');
	        if (row){
	        	window.location="${ctx}/reply/queryReply.action?topicid="+row.topicid	
                  /* $.post('${ctx}/reply/queryReply.action',{topicid:row.topicid},function(result){
                  	$('#dg').datagrid('reload');    //刷新表          
                  }); */
	        }else{
	        	$.messager.show({    // show error message
	                title: '提示',
	                msg: '请选择操作行',
	            });
	        }
		}
		
		var um=UM.getEditor('content');
	</script>	    
  </body>
</html>
